package com.zhhtech.zhh.ui.activity.main

import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.view.isVisible
import com.lxj.xpopup.XPopup
import com.zhhtech.zhh.bean.HomeCaseBean
import com.zhhtech.zhh.databinding.ActivityCaseDetailBinding
import com.zhhtech.zhh.ui.adapter.mSmartGlideImageLoader
import com.zhhtech.zhh.ui.base.BaseActivity
import com.zhhtech.zhh.ui.helper.InjectBundle
import com.zhhtech.zhh.ui.utils.GlideUtils

class CaseDetailActivity : BaseActivity<ActivityCaseDetailBinding>() {
    private val case: HomeCaseBean by InjectBundle()
    private val position: String by InjectBundle()
    override fun initView() {
        if ("home" == position) {
            vb.tv1.text = "用户情况"
            vb.tvTitle1.text = case.username
            vb.tvTitle2.text = case.work
            vb.tvContent1.text = case.loanType
            vb.tvContent2.text = "欠款:${case.money}"
            vb.llTitle.isVisible = true
            vb.llContent.isVisible = true
            vb.tvTitle.isVisible = false
            vb.tvContent.isVisible = false
        } else {
            vb.tvTitle.text = case.title
            vb.tvContent.text = case.content
            vb.llTitle.isVisible = false
            vb.llContent.isVisible = false
            vb.tvTitle.isVisible = true
            vb.tvContent.isVisible = true
        }
        if (case.images.isNotEmpty()) {
            case.images.forEachIndexed { index, it ->
                val imageView = ImageView(mThis)
                vb.llImage.addView(imageView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                GlideUtils.intoView(mThis, it, imageView)
                imageView.setOnClickListener {
                    XPopup.Builder(mThis)
                        .asImageViewer(imageView, index, case.images as List<Any>?, null, mSmartGlideImageLoader)
                        .show()
                }
            }
        }
        vb.tvSolution.text = case.solution
    }
}